package com.weishi.project.training.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.weishi.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import com.weishi.project.training.domain.ShipSpeed;
import com.weishi.project.training.service.IShipSpeedService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * 船速仪Controller
 */
@RestController
@RequestMapping("/training/shipSpeed")
public class ShipSpeedController extends BaseController {


    /**
     * 船速仪 接口
     */
    @Autowired
    private IShipSpeedService shipSpeedService;



    @ApiOperation("查询船速仪列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public TableDataInfo list(ShipSpeed shipSpeed) {
        startPage();
        List<ShipSpeed> list = shipSpeedService.selectShipSpeedList(shipSpeed);
        return getDataTable(list);
    }


    /**
     * 导出船速仪列表
     */
    @Log(title = "船速仪", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShipSpeed shipSpeed) {
        List<ShipSpeed> list = shipSpeedService.selectShipSpeedList(shipSpeed);
        ExcelUtil<ShipSpeed> util = new ExcelUtil<ShipSpeed>(ShipSpeed.class);
        return util.exportExcel(list, "speed");
    }


    @ApiOperation("查询船速仪详情")
    @RequestMapping(value = "/getInfo", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getInfo(Long id) {
        return AjaxResult.success(shipSpeedService.getById(id));
    }


    @ApiOperation("新增船速仪")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult add(@RequestBody ShipSpeed shipSpeed) {
        shipSpeed.setCtime(new Date());
        shipSpeedService.save(shipSpeed);
        return AjaxResult.success();
    }


    @ApiOperation("修改船速仪")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult edit(@RequestBody ShipSpeed shipSpeed) {
        shipSpeedService.updateById(shipSpeed);
        return AjaxResult.success();
    }


    @ApiOperation("删除船速仪")
    @Log(title = "shipSpeed", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteById/{ids}")
    public AjaxResult deleteById(@PathVariable Integer[] ids) {
        shipSpeedService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }





}